package JFrame.User;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.util.List;

import JFrame.Tools;
import entity.Mail;
import serive.UserService;
import serive.UserServiceImpl;

public class EnquiryMail extends JFrame {
    JLabel l_tip;
    JTable table_book;

    UserService userService=new UserServiceImpl();
    String uid;
    public EnquiryMail(String uid) {
        this.uid=uid;
        initializing();
        this.setTitle("查询快件窗体");
        this.setSize(900, 650);
        this.setVisible(true);
    }
    public void initializing(){
        List<Mail> mailList = userService.queryMail(uid);
        String address = userService.queryAddress(uid);
        String Telephone = userService.queryTelephone(uid);

        int mailNum = mailList.size();
        JTextField cur_Mail =new JTextField("查询到您有",SwingConstants.RIGHT);
        JTextField cur_MailNum =new JTextField(mailNum+"个快件",SwingConstants.LEFT);
        Tools.setBorders(cur_Mail,cur_MailNum);
        this.setLayout(null);
        Object[] title = {"快件ID","收件人姓名","到站时间","派送状况","派送完成时间","电话","地址",};
        Object[][] mailLists = new String[mailNum+1][7];
        for(int i = 0; i < mailNum ; i++) {
            for(int j = 0; j < 7; j++) {
                switch(j) {
                    case 0: mailLists[i][j] =mailList.get(i).getmId();break;
                    case 1: mailLists[i][j] =mailList.get(i).getmName();break;
                    case 2: mailLists[i][j] =mailList.get(i).getArrivalTime();break;
                    case 3: mailLists[i][j] =mailList.get(i).getMailState();break;
                    case 4: mailLists[i][j] =mailList.get(i).getCompletionTime();break;
                    case 5: mailLists[i][j] =Telephone;break;
                    case 6: mailLists[i][j] =address;break;
                }
            }
        }

        table_book = new JTable(mailLists,title);
        table_book.setSize(900,500);
        l_tip=new JLabel();
        l_tip.setBounds(10, 50, 200, 30);
        l_tip.setText("查询到您一共有"+mailNum+"个快件");
        this.add(l_tip);

        JScrollPane pane = new JScrollPane(table_book);
        pane.setBounds(10, 80, 850, 500);
        this.add(pane);

    }

}

